import requests
from lxml import etree
header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"}
def lesson1():
    url = 'https://www.imooc.com/course/list'
    response = requests.get(url,headers=header)
    print(response.status_code)
    ehtml = etree.HTML(response.text)
    print(ehtml.xpath("//p[@class='title ellipsis2']/text()"))
    print(ehtml.xpath("//p[@class='one']/text()"))
    print(ehtml.xpath("//p[@class='two clearfix']/span/text()"))
    print(ehtml.xpath("//div[@class='img']//@style"))
def lesson2():
    url = 'http://www.1ppt.com/moban/'
    response = requests.get(url,headers=header)
    response.encoding = response.apparent_encoding
    print(response.status_code)
    ehtml = etree.HTML(response.text)
    print(ehtml.xpath("//li/h2/a/text()"))
    text1 = ehtml.xpath("//li/span/text()[2]")
    for i in text1:
        print(i[1:])
    print(ehtml.xpath("//li/a/img//@src"))
def lesson3():
    url = 'https://jh.lianjia.com/ershoufang/'
    response = requests.get(url,headers=header)
    response.encoding = response.apparent_encoding
    print(response.status_code)
    ehtml = etree.HTML(response.text)
    print(ehtml.xpath("//div[@class='title']/a/text()"))
    print(ehtml.xpath("//div[@class='houseInfo']/text()"))
    print(ehtml.xpath("//div[@class='title']/a/text()"))
    print(ehtml.xpath("//div[@class='title']/a/text()"))
def lesson4():
    url = 'https://hotel.qunar.com/'
    response = requests.get(url,headers=header)
    response.encoding = response.apparent_encoding
    print(response.status_code)
    ehtml = etree.HTML(response.text)
    print(ehtml.xpath("//li[@class='item']/a/p[2]/text()"))
    text1 = (ehtml.xpath("//div[@class='comm_box clearfix']/p/span/text()"))
    text2 = (ehtml.xpath("//div[@class='comm_box clearfix']/p[@class='score']/text()"))
    for i in range(len(text1)):
        print(text1[i]+" "+text2[i])
    print(ehtml.xpath("//div[@class='comm_box clearfix']/p[@class='comm_num']/text()"))
    text3 = ehtml.xpath("//p[@class='price']/span[@class='y rmb']/text()")
    text4 = ehtml.xpath("//p[@class='price']/text()")
    text5 = ehtml.xpath("//p[@class='price']/span[@class='qi']/text()")
    for i in range(len(text3)):
        print(text3[i]+text4[i]+text5[i])
def lesson5():
    url = 'https://china.nba.com/static/data/league/playerstats_All_All_All_0_All_false_2021_2_All_Team_points_All_perGame.json'
    response = requests.get(url,headers=header)
    response.encoding = response.apparent_encoding
    print(response.status_code)
    xhtml = response.json()
    #print(res.text)
    for i in range(50):
        print(xhtml['payload']['players'][i]['playerProfile']['displayName'])
        print(xhtml['payload']['players'][i]['teamProfile']['displayAbbr'])
        print(xhtml['payload']['players'][i]['statAverage']['pointsPg'])
lesson1()